package com;

import Util.ActionContext;
import Util.HandlerDefinition;
import a.BeanFactory;
import a.annotation.Component;
import a.util.StringUtil;
import factory.HandlerFactory;

import static Util.ActionContext.*;

public class ContainerHandlerFactory implements HandlerFactory{

    private BeanFactory beanFactory ;
    public ContainerHandlerFactory(BeanFactory beanFactory) {
        this.beanFactory = beanFactory;
    }
    @Override
    public Object handler(HandlerDefinition definition) {
        String value = definition.getClazz().getAnnotation(Component.class).value();
        if("".equals(value)) {
            value = StringUtil.toLowerCaseFirstOne(definition.getClazz().getSimpleName()) ;
        }
        Object bean = beanFactory.getBean(value);
        return bean;
    }
}
